home *** CD-ROM | disk | FTP | other *** search
- //
- // INPTEST.CPP
- //
- // Test program for NumInputLine
- //
-
- #define Uses_MsgBox
- #define Uses_TEvent
- #define Uses_TApplication
- #define Uses_TKeys
- #define Uses_TRect
- #define Uses_TMenu
- #define Uses_TMenuBar
- #define Uses_TMenuItem
- #define Uses_TStatusLine
- #define Uses_TStatusItem
- #define Uses_TStatusDef
- #define Uses_TDeskTop
- #define Uses_TDialog
- #define Uses_TLabel
- #define Uses_TButton
- #include <tv.h>
-
- #include <strstream.h>
- #include "numinp.h"
-
- const cmAbout = 100;
- const cmTest = 101;
-
- class Shell : public TApplication {
-
- public:
-
- Shell();
- static TMenuBar *initMenuBar( TRect r );
- static TStatusLine *initStatusLine( TRect r );
- void handleEvent( TEvent& event );
- void idle();
-
- private:
-
- void About();
- void Test();
- };
-
- Shell::Shell() : TProgInit (
- &Shell::initStatusLine,
- &Shell::initMenuBar,
- &Shell::initDeskTop
- )
- {
- }
-
- TMenuBar *Shell::initMenuBar( TRect r )
- {
- r.b.y = r.a.y + 1;
-
- TMenuItem& mI =
- *new TMenuItem( "~T~est", cmTest, kbNoKey, hcNoContext );
-
- return new TMenuBar( r, new TMenu( mI ) );
- }
-
-
- TStatusLine *Shell::initStatusLine( TRect r )
- {
- r.a.y = r.b.y - 1;
-
- TStatusLine *sl = new TStatusLine( r,
- *new TStatusDef(0, 0xFFFF) +
- *new TStatusItem( 0, kbF10, cmMenu ) +
- *new TStatusItem( "~Alt-X~ Quit", kbAltX, cmQuit ) );
-
- return sl;
- }
-
- void Shell::handleEvent( TEvent &event )
- {
- TApplication::handleEvent(event);
-
- if (event.what == evCommand)
- {
- switch (event.message.command)
- {
- case cmAbout:
- About();
- break;
- case cmTest:
- Test();
- break;
- default:
- break;
- }
- }
- }
-
- void Shell::idle()
- {
- // select menu bar if deskTop empty
-
- if( deskTop->current == 0
- && !menuBar->getState( sfSelected ) )
- {
- TEvent event;
- event.what = evCommand;
- event.message.command = cmMenu; // put a cmMenu event in queue
- putEvent( event );
- }
- }
-
- void Shell::About()
- {
- messageBox( "\003Numeric Input Line Demo",
- mfInformation | mfOKButton );
- }
-
-
-
-
- // structure to get data into and out of the dialog box.
- // Note that the structure contains the types we're interested
- // in, not strings, as would be need for a normal TInputLine.
-
- struct IntDbl {
- int ival;
- double dval;
- };
-
-
- // Build a dialog box demonstrating IntInputLine and DoubleInputLine
-
- void Shell::Test()
- {
- TDialog *d = new TDialog( TRect(0,0,30,10), "Test" );
- d->options |= ofCentered;
-
- IntInputLine *il = new IntInputLine( TRect(11,2,21,3), 6 );
- d->insert( new TLabel( TRect(2,2,10,3), "Integer", il ) );
- d->insert( il );
-
- DoubleInputLine *dl = new DoubleInputLine( TRect(11,4,21,5), 8 );
- d->insert( new TLabel( TRect(2,4,10,5), "Double", dl ) );
- d->insert( dl );
-
- d->insert( new TButton( TRect(10,7,20,9), "O~K~", cmOK, bfDefault ) );
- il->select();
-
- IntDbl buf = { 123, 1.23 }; // stuff some initial values
- d->setData( &buf );
-
- ushort cmd = deskTop->execView( d ); // execute the dialog
-
- if( cmd != cmCancel )
- {
- d->getData( &buf ); // read the input values
-
- char msg[40]; // display them
- ostrstream os( msg, 40 );
- os << "\003You entered: " << buf.ival
- << " and " << buf.dval << ends;
-
- messageBox( os.str(), mfInformation | mfOKButton );
- }
-
- destroy( d ); // clean up
- }
-
- int main()
- {
- TEvent init;
- init.what = evCommand;
- init.message.command = cmAbout; // make a cmAbout command event
-
- Shell shell;
- shell.putEvent(init); // put it in the queue to pop up
- shell.run(); // About box when program starts
- return 0;
- }
-
-